package com.groovy.base

import org.junit.Test

class GroovyIO {


    static void main(String[] args) {
        new File("C:/com.groovy.base.Example.txt").eachLine {
            line -> println "line : $line";
        }
    }


    @Test
    void fullContent() {
        def file = new File("C:/com.groovy.base.Example.txt")
        println file.text
    }

    /**
     * 写内容到文件
     */
    @Test
    void writeFile() {
        new File('C:/','com.groovy.base.Example.txt').withWriter('utf-8') {
            writer -> writer.writeLine('Hello World   ffff')
        }
    }

    @Test
    void getFileLength() {
        File file = new File("C:/com.groovy.base.Example.txt")
        println "The file ${file.absolutePath} has ${file.length()} bytes"

    }
}
